var i;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var Item_Shop_TodayItem_UIBindings = require("AA_Item_Shop_TodayItem_UIBindings");
var ResKeeper = require("AA_ResKeeper");
var Const_Hall = require("AA_Const_Hall");
var Excel = require("AA_Excel");
var HallManager = require("AA_HallManager");
var TipsManager = require("AA_TipsManager");
var PlayerDataManager = require("AA_PlayerDataManager");
var UIManager = require("AA_UIManager");
var UIConfig_Home = require("AA_UIConfig_Home");
var BundleConfig = require("AA_BundleConfig");
var CommonUtils = require("AA_CommonUtils");
var ADManager = require("AA_ADManager");
var EventManager = require("AA_EventManager");
var EvenType = require("AA_EvenType");
var RedPointControl = require("AA_RedPointControl");
var HallGlobalVariable = require("AA_HallGlobalVariable");
var _decorator = cc._decorator;
var _ccclass = _decorator.ccclass;
var _property = _decorator.property;

var _def_Item_Shop_TodayItem = function (e) {
  function _creator() {
    var t = null !== e && e.apply(this, arguments) || this;
    t.auto_ui = null;
    t.childIndex = 0;
    t.isStart = true;
    return t;
  }
  __extends(_creator, e);
  _creator.prototype.StartSet = function (e) {
    var t = this.node.getChildByName("redPoint");
    t && (t.active = 0 == e);
    this.childIndex = e;
    this.auto_ui.node_discountNode.active = false;
    var o = Excel.Excel.shopControl(1);
    this.auto_ui.node_goldbg.active = 0 == e;
    this.auto_ui.btn_buyBtn.interactable = true;
    if (0 == e) {
      if (this.isStart) {
        this.isStart = false;
        this.auto_ui.txt_nameLabel.string = "钻石";
        this.auto_ui.txt_countLabel.string = "x" + o.todayDiamondCount;
      }
      if (0 == HallManager.HallMgr.shopData.todayBuyDiamondCount) {
        this.auto_ui.txt_priceLabel.string = "免费";
        this.auto_ui.node_videoIcon.active = false;
      } else {
        var n = o.getDiamondTime - HallManager.HallMgr.shopData.todayBuyDiamondCount + 1;
        if (n <= 0) {
          this.auto_ui.txt_priceLabel.string = "已售罄";
          this.auto_ui.node_videoIcon.active = false;
          this.auto_ui.btn_buyBtn.interactable = false;
        } else {
          this.auto_ui.txt_priceLabel.string = "免费(" + n + ")";
          this.auto_ui.node_videoIcon.active = true;
        }
      }
    } else {
      var i = HallManager.HallMgr.shopData.todayShopArray[e - 1];
      this.todayShopData = Excel.Excel.todayShop(i.shopId);
      this.LoadSprite(this.todayShopData.shuiguoId);
      this.auto_ui.txt_nameLabel.string = this.todayShopData.showName;
      this.auto_ui.txt_countLabel.string = "x" + this.todayShopData.count;
      if (1 == i.discount) {
        this.auto_ui.node_discountNode.active = false;
      } else {
        this.auto_ui.node_discountNode.active = true;
        this.auto_ui.txt_discountLabel.string = 10 * i.discount + "折";
      }
      if (i.canBuyCount > 0) {
        this.auto_ui.node_goldIcon.active = i.richType == Const_Hall.RichType.金币;
        this.auto_ui.node_diamondIcon.active = i.richType == Const_Hall.RichType.钻石;
        this.auto_ui.txt_priceLabel.string = "" + i.price;
      } else {
        this.auto_ui.node_goldIcon.active = false;
        this.auto_ui.node_diamondIcon.active = false;
        this.auto_ui.txt_priceLabel.string = "已售罄";
        this.auto_ui.btn_buyBtn.interactable = false;
      }
    }
  };
  _creator.prototype.LoadSprite = function (e) {
    return __awaiter(this, undefined, undefined, function () {
      var t = this;
      return __generator(this, function () {
        this._loadRes(BundleConfig.BundleNames.Common, "common/" + "res/player/player" + (e - 1e3) + "_1", cc.SpriteFrame).then(function (e) {
          t.auto_ui.sp_iconSprite.spriteFrame = e;
          CommonUtils.default.LimitSpriteMaxSize(t.auto_ui.sp_iconSprite, Const_Hall.equipIconSize);
        });
        this._loadRes(BundleConfig.BundleNames.Common, "common/" + "res/quality/quality_" + Excel.Excel.shuiguo(e).quality, cc.SpriteFrame).then(function (e) {
          t.auto_ui.sp_qualitySprite.spriteFrame = e;
        });
        return [2];
      });
    });
  };
  _creator.prototype.onLoad = function () {
    this.auto_ui.addClickListener(this._clickListener, this);
  };
  _creator.prototype._clickListener = function (e) {
    switch (e) {
      case this.auto_ui.btn_buyBtn:
        this.BuyThis();
    }
  };
  _creator.prototype.BuyThis = function () {
    var e = this;
    if (0 == this.childIndex) {
      var t = Excel.Excel.shopControl(1);
      if (0 == t.gold1Time - HallManager.HallMgr.shopData.todayBuyDiamondCount + 1) {
        return void TipsManager.TipMgr.showToast("已售罄");
      }
      var o = new Const_Hall.GetItemsData();
      o.ids = [HallGlobalVariable.default.diamondId];
      o.counts = [t.todayDiamondCount];
      o.clickCallBack = function () {
        TipsManager.TipMgr.showToast("购买成功，获得钻石" + t.todayDiamondCount);
        e.StartSet(e.childIndex);
      };
      if (0 == HallManager.HallMgr.shopData.todayBuyDiamondCount) {
        PlayerDataManager.PlayerDataMgr.AddDiamond(t.todayDiamondCount);
        HallManager.HallMgr.shopData.todayBuyDiamondCount++;
        HallManager.HallMgr.SaveShopData();
        EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.MainRedPointChange, RedPointControl.RedPointType.freeDiamond);
        UIManager.default.open(BundleConfig.BundleNames.Home, UIConfig_Home.UIView_Home.UI_GetItems, o);
      } else {
        ADManager.ADMgr.showRewardedVideo("商城视频购买钻石", function () {
          PlayerDataManager.PlayerDataMgr.AddDiamond(t.todayDiamondCount);
          HallManager.HallMgr.shopData.todayBuyDiamondCount++;
          HallManager.HallMgr.SaveShopData();
          UIManager.default.open(BundleConfig.BundleNames.Home, UIConfig_Home.UIView_Home.UI_GetItems, o);
        });
      }
    } else {
      var n = HallManager.HallMgr.shopData.todayShopArray[this.childIndex - 1];
      if (n.canBuyCount <= 0) {
        TipsManager.TipMgr.showToast("已售罄");
      } else {
        var i = this;
        var a = new Const_Hall.ShopItemInfoData();
        a.titleName = this.auto_ui.txt_nameLabel.string;
        a.count = this.todayShopData.count;
        a.richType = n.richType;
        a.price = n.price;
        a.infoStr = this.todayShopData.describe;
        a.iconSpriteFrame = this.auto_ui.sp_iconSprite.spriteFrame;
        a.qualitySpriteFrame = this.auto_ui.sp_qualitySprite.spriteFrame;
        a.clickCallBack = function () {
          if (n.richType == Const_Hall.RichType.金币) {
            if (!PlayerDataManager.PlayerDataMgr.SubGold(n.price)) {
              return;
            }
          } else if (!PlayerDataManager.PlayerDataMgr.SubDiamond(n.price)) {
            return;
          }
          PlayerDataManager.PlayerDataMgr.AddEquipFragments(i.todayShopData.shuiguoId, i.todayShopData.count);
          HallManager.HallMgr.shopData.todayShopArray[i.childIndex - 1].canBuyCount--;
          HallManager.HallMgr.SaveShopData();
          var e = new Const_Hall.GetItemsData();
          e.ids = [i.todayShopData.shuiguoId];
          e.counts = [i.todayShopData.count];
          e.clickCallBack = function () {
            TipsManager.TipMgr.showToast("购买成功，获得" + i.todayShopData.showName + "碎片" + i.todayShopData.count);
            i.StartSet(i.childIndex);
          };
          UIManager.default.open(BundleConfig.BundleNames.Home, UIConfig_Home.UIView_Home.UI_GetItems, e);
        };
        UIManager.default.open(BundleConfig.BundleNames.Home, UIConfig_Home.UIView_Home.UI_ShopItemInfo, a);
      }
    }
  };
  __decorate([_property(Item_Shop_TodayItem_UIBindings.default)], _creator.prototype, "auto_ui", undefined);
  return __decorate([_ccclass], _creator);
}(ResKeeper.default);
exports.default = _def_Item_Shop_TodayItem;